package bz.yfw.example.s3blazeds.part2.model.convert
{
	import bz.yfw.example.s3blazeds.part2.model.view.EmpViewModel;
	
	import mx.graphics.codec.JPEGEncoder;
	import bz.yfw.example.s3blazeds.part2.model.ro.EmpRemotoObject;

	public class EmpConverter
	{
		public function EmpConverter()
		{
		}
		
		public static function convertRemotoObject(vm:EmpViewModel):EmpRemotoObject {
			var model:EmpRemotoObject = new EmpRemotoObject();
			// 名前
			model.name = vm.name;
			// 性別
			model.sex = vm.sex;
			// 誕生日
			var birthDate:Date = new Date();
			birthDate.fullYear = int(vm.year);
			birthDate.month = int(vm.month) + 1;
			birthDate.date = int(vm.date);
			model.birthDate = birthDate;
			
			// 住所
			model.address = vm.address;
			// Eメール
			model.email = vm.emailL + "@" + vm.emailR;
			// 電話番号
			model.tel = vm.telL + "-" + vm.telC + "-" + vm.telR;
			
			// 役職
			model.position = vm.position;
			// 入社日
			var enterCompanyDate:Date = new Date();
			birthDate.fullYear = int(vm.enterCompanyY);
			birthDate.month = int(vm.enterCompanyM) + 1;
			birthDate.date = int(vm.enterCompanyD);
			model.enterCompanyDate = enterCompanyDate;
			
			// 写真
			var encoder:JPEGEncoder = new JPEGEncoder();
			model.shashin = encoder.encode(vm.shashin);
			
			return model;
		}
	}
}